<?php

namespace App\Api\Http\ApiControllers;

use App\Application\ItemService;
use Illuminate\Http\Request;

class ItemController extends Controller
{
    /**
     * @var ItemService
     */
    protected $item_service;

    public function __construct(ItemService $item_service)
    {
        $this->item_service = $item_service;
    }

    /**
     * 首页 信息列表
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(Request $request)
    {
        $per_page = $request->get('per_page', 10);
        $data = $this->item_service->latestValidItems($per_page);

        return response()->json($data);
    }

    public function show($id)
    {
        $info = $this->item_service->show($id, access()->id());

        return response()->json($info);
    }
}
